package com.example.springboot09.原型模式;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Date;

/**
 * @ClassName 原型模式
 * @Description TODO
 * @Author tianqinglong
 * @Date 16:40 2022/7/25
 * @Version 1.0
 **/
public class 原型模式 {
}
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
class Video implements Cloneable{
    private String name;
    private Date createTime;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Object obj = super.clone();
        //实现深克隆~
        Video v = (Video) obj;
        v.createTime = (Date) this.createTime.clone();//将这个对象的属性也进行克隆~
        return obj;
    }
}
class Bilibili {
    public static void main(String[] args) throws CloneNotSupportedException {
        Date date = new Date();
        Video v1 = new Video("狂神说java", date);
        Video v2 = (Video) v1.clone();
        System.out.println("v1=>"+v1);
        System.out.println("v2=>"+v2);
        System.out.println("=======");
        date.setTime(21312231); //没有发生改变
        System.out.println("v1=>"+v1);
        System.out.println("v2=>"+v2);
    }
}